/**
 * 
 */
package com.zito.web.www;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.downlove.template.freemarker.FreeMarkerEngine;

import com.zito.ErrMsgException;
import com.zito.bean.Admin;
import com.zito.bean.Advice;
import com.zito.bean.Article;
import com.zito.bean.Columnz;
import com.zito.bean.Invest;
import com.zito.manager.AdsManager;
import com.zito.manager.AdsTypeManager;
import com.zito.manager.AdviceManager;
import com.zito.manager.AlbumManager;
import com.zito.manager.AlbumphotoManager;
import com.zito.manager.ArticleManager;
import com.zito.manager.ArticlefilesManager;
import com.zito.manager.ArticlephotosManager;
import com.zito.manager.ColumnManager;
import com.zito.manager.ContributeManager;
import com.zito.manager.InvestManager;
import com.zito.manager.MasterSession;
import com.zito.manager.PartyBuildingManager;
import com.zito.manager.VideoManager;
import com.zito.manager.WeblinkManager;

/**
 * @author YunHai-Home
 * 
 */
public class Master {

	private String TemplatePath = "/master/";
	
	public MasterSession session() {
		return MasterSession.get();
	}
	
	/**
	 * 默认后台主界面
	 * 
	 * @param request
	 * @param response
	 */
	public void index(HttpServletRequest request, HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		FreeMarkerEngine.action(fm, TemplatePath + "main.html");
	}

	/**
	 * 管理员登录界面
	 * 
	 * @param request
	 * @param response
	 */
	public void login(HttpServletRequest request, HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		FreeMarkerEngine.action(fm, TemplatePath + "login.html");
	}
	
	/**
	 * 退出登录，返回登录界面
	 * 
	 * @param request
	 * @param response
	 */
	public void loginOut(HttpServletRequest request, HttpServletResponse response) {
		try {
			session().clearLogin();
			response.sendRedirect(request.getContextPath()
					+ TemplatePath + "login");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 框架左菜单部分
	 * 
	 * @param request
	 * @param response
	 */
	public void menu(HttpServletRequest request, HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		FreeMarkerEngine.action(fm, TemplatePath + "menu.html");
	}

	/**
	 * 管理后台默认欢迎页面
	 * 
	 * @param request
	 * @param response
	 */
	public void welcome(HttpServletRequest request, HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		FreeMarkerEngine.action(fm, TemplatePath + "welcome.html");
	}

	/**
	 * 管理人员设置界面
	 * 
	 * @param request
	 * @param response
	 */
	public void AdminUser(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		Admin admin = new Admin();
		fm.put("adminlist", admin.allList());
		FreeMarkerEngine.action(fm, TemplatePath + "AdminUser.html");
	}

	/**
	 *   管理列表
	 * 
	 * @param request
	 * @param response
	 */
	public void ColumnList(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		ColumnManager manager = new ColumnManager();
		List<Columnz> List = new ArrayList<Columnz>();
		try {
			List = manager.getSpecialList();
		} catch (Exception e) {
			e.printStackTrace();
		}
		fm.put("columnlist", List);
		FreeMarkerEngine.action(fm, TemplatePath + "ColumnList.html");
	}

	/**
	 * 文章列表
	 * 
	 * @param request
	 * @param response
	 */
	public void ArticleList(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		ColumnManager manager = new ColumnManager();
		List<Columnz> columnList = new ArrayList<Columnz>();
		try {
			columnList = manager.getListAll();
		} catch (ErrMsgException e) {
			e.printStackTrace();
		}
		fm.put("columnlist", columnList);
		fm.put("manager", new ArticleManager());
		FreeMarkerEngine.action(fm, TemplatePath + "ArticleList.html");
	}

	/**
	 * 编辑或修改文章
	 * 
	 * @param request
	 * @param response
	 */
	public void ArticleEdit(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		ArticleManager article = new ArticleManager();
		ColumnManager manager = new ColumnManager();
		List<Columnz> columnList = new ArrayList<Columnz>();
		List<Columnz> specialList = new ArrayList<Columnz>();
		com.zito.bean.Article obj = new com.zito.bean.Article();
		try {
			columnList = manager.getColumnzList();
			specialList = manager.getSpecialList();
			obj = article.getArticle();
		} catch (ErrMsgException e) {
			e.printStackTrace();
		}
		fm.put("columnlist", columnList);
		fm.put("speciallist", specialList);
		fm.put("article", obj);
		fm.put("photos", new ArticlephotosManager());
		fm.put("files", new ArticlefilesManager());
		FreeMarkerEngine.action(fm, TemplatePath + "ArticleEdit.html");
	}

	/**
	 * 图集管理列表
	 * 
	 * @param request
	 * @param response
	 */
	public void AlbumList(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		fm.put("albums", new AlbumManager());
		FreeMarkerEngine.action(fm, TemplatePath + "AlbumList.html");
	}

	/**
	 * 添加新的图集
	 * 
	 * @param request
	 * @param response
	 */
	public void AlbumEdit(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		AlbumManager obj = new AlbumManager();
		fm.put("album", obj.getAlbum());
		fm.put("photos", new AlbumphotoManager());
		FreeMarkerEngine.action(fm, TemplatePath + "AlbumEdit.html");
	}

	/**
	 * 视频管理列表
	 * 
	 * @param request
	 * @param response
	 */
	public void VideoList(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		fm.put("manager", new VideoManager());
		FreeMarkerEngine.action(fm, TemplatePath + "VideoList.html");
	}

	/**
	 * 视频编辑页面
	 * 
	 * @param request
	 * @param response
	 */
	public void VideoEdit(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		VideoManager obj = new VideoManager();
		fm.put("video", obj.getVideo());
		FreeMarkerEngine.action(fm, TemplatePath + "VideoEdit.html");
	}
	
	/**
	 * 
	 * 机关党建专版电子版列表页面
	 */
	
	public void PartyBuildingList(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		fm.put("manager", new PartyBuildingManager());
		FreeMarkerEngine.action(fm, TemplatePath + "PartyBuildingList.html");
	}

	/**
	 * 机关党建专版电子版编辑页面
	 * @param request
	 * @param response
	 */
	public void PartyBuildingEdit(HttpServletRequest request,
			HttpServletResponse response) {
		  FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
	      PartyBuildingManager manager = new PartyBuildingManager();
	      Article obj = new Article();  
		 try {
	        obj = manager.getPartyBuilding();
		 } catch (ErrMsgException e) {
			e.printStackTrace();
		 }
		fm.put("article", obj);
		fm.put("manager", manager);
		FreeMarkerEngine.action(fm, TemplatePath + "PartyBuildingEdit.html");
	}
	
	/**
	 * 党员投诉管理 列表
	 * 
	 * @param request
	 * @param response
	 */
	public void AdviceList(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		AdviceManager manager = new AdviceManager();
		fm.put("manager", manager);
		FreeMarkerEngine.action(fm, TemplatePath + "AdviceList.html");
	}
	
	/**
	 * 党员投诉管理 编辑页面
	 * 
	 * @param request
	 * @param response
	 */
	public void AdviceEdit(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		AdviceManager manager = new AdviceManager();
		Advice obj = new Advice();
		try {
			obj = manager.getAdviceInfo();
		} catch (Exception e) {
			e.printStackTrace();
		}
		fm.put("advice", obj);
		fm.put("manager", manager);
		FreeMarkerEngine.action(fm, TemplatePath + "AdviceEdit.html");
	}
	
	/**
	 * 在线调查列表
	 * 
	 * @param request
	 * @param response
	 */
	public void InvestList(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		InvestManager manager = new InvestManager();
		fm.put("manager", manager);
		FreeMarkerEngine.action(fm, TemplatePath + "InvestList.html");
	}
	
	/**
	 * 在线调查统计页面
	 * 
	 * @param request
	 * @param response
	 */
	public void InvestStatistics(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		InvestManager manager = new InvestManager();
		Invest obj = new Invest();
		try {
			obj = manager.getInvestInfo();
		} catch (Exception e) {
			e.printStackTrace();
		}
		fm.put("invest", obj);
		fm.put("manager", manager);
		FreeMarkerEngine.action(fm, TemplatePath + "InvestStatistics.html");
	}

	/**
	 * 在线调查编辑页面
	 * 
	 * @param request
	 * @param response
	 */
	public void InvestEdit(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		InvestManager manager = new InvestManager();
		Invest obj = new Invest();
		try {
			obj = manager.getInvestInfo();
		} catch (Exception e) {
			e.printStackTrace();
		}
		fm.put("manager", manager);
		fm.put("invest", obj);
		FreeMarkerEngine.action(fm, TemplatePath + "InvestEdit.html");
	}
	
	/**
	 * 
	 * 在线投稿管理 列表
	 */
	public void ContributeManage(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		ColumnManager manager = new ColumnManager();
		List<Columnz> columnList = new ArrayList<Columnz>();
		try {
			columnList = manager.getListAll();
		} catch (ErrMsgException e) {
			e.printStackTrace();
		}
		fm.put("columnlist", columnList);
		fm.put("manager", new ContributeManager());
		FreeMarkerEngine.action(fm, TemplatePath + "ContributeManage.html");
	}
	
	/**
	 * 在线投稿管理 编辑页面
	 * @param request
	 * @param response
	 */
	public void ContributeManageEdit(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		ContributeManager manager = new ContributeManager();
		ColumnManager column = new ColumnManager();
		List<Columnz> columnList = new ArrayList<Columnz>();
		List<Columnz> specialList = new ArrayList<Columnz>();
		Article obj = new Article();
		try {
			columnList = column.getColumnzList();
			specialList = column.getSpecialList();
			obj = manager.getArticle();
		} catch (Exception e) {
			e.printStackTrace();
		}
		fm.put("article", obj);
		fm.put("columnlist", columnList);
		fm.put("speciallist", specialList);
		fm.put("photos", new ArticlephotosManager());
		fm.put("files", new ArticlefilesManager());
		FreeMarkerEngine.action(fm, TemplatePath + "ContributeManageEdit.html");
	}
	
	/**
	 * 友情链接管理
	 * 
	 * @param request
	 * @param response
	 */
	public void webLink(HttpServletRequest request, HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		fm.put("links", new WeblinkManager());
		FreeMarkerEngine.action(fm, TemplatePath + "webLink.html");
	}

	public void logoLink(HttpServletRequest request,
			HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		fm.put("links", new WeblinkManager());
		FreeMarkerEngine.action(fm, TemplatePath + "logoLink.html");
	}
	
	/**
	 * 广告类型查看
	 * 
	 * @param request
	 * @param response
	 */
	public void AdsType(HttpServletRequest request, HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		AdsTypeManager obj = new AdsTypeManager();
		fm.put("types", obj.allList());
		FreeMarkerEngine.action(fm, TemplatePath + "AdsType.html");
	}

	/**
	 * 广告编辑
	 * 
	 * @param request
	 * @param response
	 */
	public void AdsEdit(HttpServletRequest request, HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		AdsManager obj = new AdsManager();
		fm.put("ads", obj.getAds());
		FreeMarkerEngine.action(fm, TemplatePath + "AdsEdit.html");
	}

	/**
	 * 广告管理
	 * 
	 * @param request
	 * @param response
	 */
	public void AdsList(HttpServletRequest request, HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		fm.put("manager", new AdsManager());
		FreeMarkerEngine.action(fm, TemplatePath + "AdsList.html");
	}
}
